function Ndkhpstb(){
    this.form=this.InitForm();
    this.tab=this.InitEleUI();
    //this.table=this.InitTable();

    $("#year").val($("#hidyear").val());
    this.form.render('select');

    this.currenttabindex=0;
    this.InitGrid();

    this.table=this.InitTableByBt();
}

Ndkhpstb.prototype.InitGrid=function (){
    var year=$("#year").val();


    var _this = this;
    window.liger.remove("listorg");
    if (_this.grid == null) {
        _this.grid = $("#listorg").ligerGrid({
            columns: [
                //{ display: '序号', width: 80, name: 'rowNum' },
                { display: '机构名称', width:250, align:'left',name: 'orgname',id:"orgname"},
                { display: '年份', width: 100, name: 'year' },
                { display: '参加考核人数', width: 100, name: 'usercount' },
                { display: '状态', width: 100, name: 'status', render: function (rowdata, rowindex, value) {
                        if(rowdata.status==1){
                            return "提交";
                        }
                        else if(rowdata.status==2){
                            return "归档";
                        }
                        else if(rowdata.status==3){
                            return "驳回";
                        }
                    } },
                { display: '说明', width: 120, name: 'remark' },

                {display: '操作', width: 100, name: 'userid', render: function (rowdata, rowindex, value) {
                        var html='';
                        if(rowdata.status===undefined){
                            if(rowdata.usercount>0){
                                html+='<img class="btn-img" src="'+ctxStatic+'/images/index/yaosu.png" onclick="vNdkhpstb.createNdkh('+rowdata.orgid+')" lay-event="shengcheng" alt="生成考核结果" title="生成考核结果">';
                            }
                        }
                        else{
                            if(rowdata.status==0||rowdata.status==3){
                                html+=' <img class="btn-img" src="'+ctxStatic+'/images/button/tijiao.png" onclick="vNdkhpstb.BmTiJiao('+rowdata.orgstatustjid+',1,'+rowdata.orgid+','+rowdata.year+')"  alt="提交" title="提交">';

                            }
                            html+=' <img class="btn-img" src="'+ctxStatic+'/images/button/detail.png" onclick="vNdkhpstb.ChangeTab(1,'+rowdata.orgid+')"  alt="详情" title="详情"> ';
                        }
                        return html;
                    }}
            ],
            pageSize: 30,
            url: "get_list_org" + '?time=' + new Date().getTime(),
            delayLoad: false,            //初始化时是否加载,为true时,不加载,为false时,则加载
            sortName: null,
            dataAction: 'server',
            parms: {
                Method: "",
                year: year
            },
            sortOrder: null,
            sourceObj: _this.grid,
            root: 'items',                       //数据源字段名
            record: 'countRecord',                    //数据源记录数字段名
            pageParmName: 'CurrentPage',               //页索引参数名，(提交给服务器)
            pagesizeParmName: 'PageSize',        //页记录数参数名，(提交给服务器)
            data: {},
            width: "100%",
            height: '100%',
            heightDiff: 0,
            rowHeight:28,
            onSuccess: function (rowdata, rowindex) { if (rowdata.status > 0) { alert(rowdata.msg) } },
            alternatingRow: true,
            border: 0,
            usePager:false,
            tree:{
                columnId:"orgname",
                idField:"orgid",
                parentIDField:"orgparentid"

            }
        })
    }
}

Ndkhpstb.prototype.InitForm=function(){
    var form;
    layui.use('form', function(){
        form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        form.on('select(year)', function (data) {
            vNdkhpstb.InitPage();
        });

        form.render();
    });
    return form;
}


Ndkhpstb.prototype.InitEleUI=function(){
    var element;
    var _this=this;
    layui.use('element', function(){
        element=layui.element;

        element.on('tab(tabcontent)', function(data){
            vNdkhpstb.currenttabindex=data.index;
            if(data.index==1){
                _this.InitTableByBt();
            }
            if(data.index==0){
                $("#hidorgid").val("");
            }
        });
    })
    return element;
}

Ndkhpstb.prototype.InitTableByBt=function (){
    var table;
    var _this=this;
    layui.use('table', function() {
        table = layui.table;
        table.init('uatmzpdsummary', {
            height : $(window).height() - 135
            ,url : 'get_ndkh_detail_list' // 数据接口
            ,page : true // 开启分页
            ,limit : 40
            ,limits:[20,40,80,100]
            ,id: 'uatmzpdsummary'
            ,method:"post"
            ,request:{
                type:'post'
            }
            ,where:{
                year: $("#year").val(),
                szdw:$("#hidorgid").val(),
                realname:$("#realname").val()
            }
            ,done: function(res, page, count){



            }


        });


        //监听工具条
        table.on('tool(uatmzpdsummary)', function(obj){

            var data = obj.data;
            if(obj.event === 'edit'){
                vNdkhpstb.opentz(data.ndkhpsid);
            }
        });


    })

    return table;



}

Ndkhpstb.prototype.opentz=function(ndkhpsid){
    top.mylayui.open({
        type: 2,
        title: '调整年度考核结果',
        shadeClose: true,
        shade: 0.5,
        area: ['600px', '300px'],
        content: 'ndkhps/ndkhtb_tz?ndkhpsid='+ndkhpsid
    });

}

Ndkhpstb.prototype.addresult=function(result,msg){
    if(result>0){
        top.mylayui.msg('操作成功', {icon: 1});
        top.mylayui.closeAll('iframe');
        //vUser.searchtable();
        vNdkhpstb.searchtable();
    }
    else{
        if(msg){
            top.mylayui.msg(msg, {icon: 0});
        }else{
            top.mylayui.msg('操作失败', {icon: 0});
        }
    }
}

Ndkhpstb.prototype.addresultorg=function(result,msg){
    if(result>0){
        top.mylayui.msg('操作成功', {icon: 1});
        top.mylayui.closeAll('iframe');
        //vUser.searchtable();
        vNdkhpstb.searchlist();
    }
    else{
        if(msg){
            top.mylayui.msg(msg, {icon: 0});
        }else{
            top.mylayui.msg('操作失败', {icon: 0});
        }
    }
}

Ndkhpstb.prototype.searchtable=function(){
    this.table.reload('uatmzpdsummary', {
        page: {
            curr: 1 //重新从第 1 页开始
        }
        ,where: {
            year: $("#year").val(),
            szdw:$("#hidorgid").val(),
            realname:$("#realname").val()
        }
    });
}


Ndkhpstb.prototype.deleteentity=function(mzpdid){
    $.ajax({
        type:"POST",
        url:"delete_mzpd",
        data:{mzpdid:mzpdid},
        beforeSend:function(XHR){

        },
        success:function(data){
            data=eval('('+data+')');
            if(data.result>0){
                top.mylayui.msg(data.msg, {icon: 1});
                document.location.reload();
            }
            else{
                top.mylayui.msg(data.msg, {icon: 0});
            }
        },
        complete:function(XHR){

        },
        error:function(){

        }
    });
}


Ndkhpstb.prototype.exportentity=function(mzpdid){
    top.ShowZheZhao();
    $.ajax({
        type:"POST",
        url:"export_mzpd",
        data:{mzpdid:mzpdid},
        beforeSend:function(XHR){

        },
        success:function(data){
            data=eval('('+data+')');
            if(data.result>0){
                //top.mylayui.msg('导出成功', {icon: 1});
                //document.location.reload();
                window.open(data.msg,'_self');

            }
            else{
                top.mylayui.msg(data.msg, {icon: 0});
            }
            top.ShowZheZhao();
        },
        complete:function(XHR){
            top.mylayui.closeAll('loading');
        },
        error:function(){

        }
    });
}

Ndkhpstb.prototype.ChangeTab=function(index,orgid){
    this.tab.tabChange('tabcontent', index);
    if(orgid){
        if(index==1){
            $("#hidorgid").val(orgid);
            vNdkhpstb.InitTableByBt();
        }
        else{
            //vUserUATMzpdHz.InitIfream(mzpdid);
        }

    }

}
Ndkhpstb.prototype.InitIfream=function(mzpdid){

    $("#getdata").attr("src","user_usasstemp_mzpd_detail?mzpdid="+mzpdid);
}


Ndkhpstb.prototype.searchlist = function () {
    var year=$("#year").val();
    this.grid.setOptions({
        newPage: 1, parms: {
            Method: "",
            year: year
        }
    });
    this.grid.loadData();
}

Ndkhpstb.prototype.InitPage=function(){
    if(vNdkhpstb.currenttabindex==0){
        vNdkhpstb.searchlist();
    }
    else if(vNdkhpstb.currenttabindex==1){
        vNdkhpstb.searchtable();
    }else{
        //vUserUsAssTempLd.InitIfream();
    }
}

Ndkhpstb.prototype.BmTiJiao=function(orgstatustjid,status,orgid,year){


    top.mylayui.open({
        type: 2,
        title: '提交',
        shadeClose: true,
        shade: 0.5,
        area: ['500px', '250px'],
        content: 'ndkhps/ndkh_status?orgstatustjid='+orgstatustjid+"&status="+status+"&orgid="+orgid+"&year="+year
    });


}

Ndkhpstb.prototype.updatestatus=function(mzpdid,status,year,quarter,userid){
    $.ajax({
        type:"POST",
        url:"update_mzpd_status",
        data:{mzpdid:mzpdid,status:status,year:year,quarter:quarter,userid:userid},
        beforeSend:function(XHR){

        },
        success:function(data){
            data=eval('('+data+')');
            if(data.result>0){
                top.mylayui.msg(data.msg, {icon: 1});
                //vOrg.searchtable();
                vUserUATMzpdHz.searchtable();
            }
            else{
                top.mylayui.msg(data.msg, {icon: 0});
            }
        },
        complete:function(XHR){

        },
        error:function(){

        }
    });
}

Ndkhpstb.prototype.openwjsm=function(userid,year,quarter){

    top.mylayui.open({
        type: 2,
        title: false,
        shadeClose: true,
        shade: 0.5,
        area: ['700px', '250px'],
        content: 'common/user_vtdp?userid='+userid+"&year="+year+"&quarter="+quarter
    });

}

Ndkhpstb.prototype.createNdkh=function(orgid){
    top.mylayui.confirm('确定要生成年度考核吗？',{icon: 0}, function(index){
        top.mylayui.close(index);
        top.ShowZheZhao();
        $.ajax({
            type:"POST",
            url:"create_ndkh",
            data:{orgid:orgid,year:$("#year").val()},
            beforeSend:function(XHR){

            },
            success:function(data){
                data=eval('('+data+')');
                if(data.result>0){
                    top.mylayui.msg(data.msg, {icon: 1});
                    //vOrg.searchtable();
                    vNdkhpstb.searchlist();
                }
                else{
                    top.mylayui.msg(data.msg, {icon: 0});
                }
                top.ShowZheZhao();
            },
            complete:function(XHR){
                top.mylayui.closeAll('loading');
            },
            error:function(){

            }
        });
    })
}


Ndkhpstb.prototype.exportentity=function(){
    top.ShowZheZhao();
    $.ajax({
        type:"POST",
        url:"export_excel_all",
        data:{year: $("#year").val(),
            szdw:$("#hidorgid").val(),
            realname:$("#realname").val(),
            khjg:""},
        beforeSend:function(XHR){

        },
        success:function(data){
            data=eval('('+data+')');
            if(data.result>0){
                //top.mylayui.msg('导出成功', {icon: 1});
                //document.location.reload();
                window.open(data.msg,'_self');

            }
            else{
                top.mylayui.msg(data.msg, {icon: 0});
            }
            top.ShowZheZhao();
        },
        complete:function(XHR){
            top.mylayui.closeAll('loading');
        },
        error:function(){

        }
    });
}


var vNdkhpstb=null;
$(function(){
    vNdkhpstb=new Ndkhpstb();
})